package com.eneat.smartrule.restAPI;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    public ResponseEntity<HttpResult<String>> handleServiceException(ServiceException ex) {
        HttpResult<String> result = new HttpResult<>("fail", false, 400, ex.desc);
        return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST);
    }
}
